<template>
  <div id="log-detail">
    <div class="row">
      <div class="col-md-12">
        <blockquote class="panel-primary small bg-info">
          <input type="text" v-model="baseUrl">
          <span v-text="logDetailUrl"></span>
          <span v-text="'&nbsp;访问日志ID:[' + detail.id + ']'"></span>
        </blockquote>
      </div>
      <div class="col-md-12">
        <table class="table table-striped table-bordered table-hover">
          <thead>
            <tr><th width="10%">项目</th><th>详情</th></tr>
          </thead>
          <tbody>
           <tr><td>module</td><td>{{ detail.module }}</td></tr>
           <tr><td>dir</td><td>{{ detail.dir }}</td></tr>
           <tr><td>controller</td><td>{{ detail.controller }}</td></tr>
           <tr><td>action</td><td>{{ detail.action }}</td></tr>
           <tr><td>textData</td><td>{{ detail.textData }}</td></tr>
           <tr><td>encryption</td><td>{{ detail.encryption }}</td></tr>
           <tr><td>sendTime</td><td>{{ detail.sendTime }}</td></tr>
           <tr><td>expiry</td><td>{{ detail.expiry }}</td></tr>
           <tr><td>appkey</td><td>{{ detail.appkey }}</td></tr>
           <tr><td>GET</td><td><div class="w1000"><pre v-text="detail.request_val.get"></pre></div></td></tr>
           <tr><td>POST</td><td><div class="w1000"><pre v-text="detail.request_val.post"></pre></div></td></tr>
           <tr><td>FILES</td><td><div class="w1000"><pre v-text="detail.request_val.file"></pre></div></td></tr>
           <tr><td>COOKIE</td><td><div class="w1000"><pre v-text="detail.request_val.cookie"></pre></div></td></tr>
           <tr><td>SESSION</td><td><div class="w1000"><pre v-text="detail.request_val.session"></pre></div></td></tr>
           <tr><td>resolve_val</td><td><div class="w1000"><pre v-text="detail.resolve_val"></pre></div></td></tr>
           <tr><td>IP</td><td>{{ detail.add_ip }}</td></tr>
           <tr><td>time</td><td>{{ detail.add_time }}</td></tr>
           <tr><td>status</td><td>{{ detail.result_status }}</td></tr>
           <tr><td>msg</td><td>{{ detail.result_msg }}</td></tr>
           <tr><td>res</td><td><div class="w1000"><pre v-text="detail.result_res"></pre></div></td></tr>     
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>
<script>
  import {baseUrl, logDetailUrl} from '../assets/js/setting.js'
  import bus from '../assets/js/bus.js'
  import mixin from '../assets/js/mixin.js'
  export default{
    created () {
      this.getDetail()
      bus.$on('changeBaseUrl', this.changeBaseUrl)
    },
    data () {
      return {
        baseUrl: baseUrl,
        logDetailUrl: logDetailUrl,
        detail: {}
      }
    },
    watch: {
      // 如果路由有变化，会再次执行该方法
      $route: 'getDetail'
    },
    mixins: [mixin],
    methods: {
      getDetail () {
        let id = this.$route.params.id ? this.$route.params.id : 0
        if (id > 0) {
          let loading = this.$loading({fullscreen: true, text: '正在载入数据...'})
          this.$http.get(this.logDetailUrl, {
            params: {
              id: id
            }
          })
          .then((response) => {
            loading.close()
            if (response.status === 200) {
              if (response.data.status === 1) {
                this.detail = response.data.res
              } else {
                this.$message(response.data.msg)
              }
            }
          })
          .catch((err) => {
            loading.close()
            console.log(err)
          })
        }
      }
    }
  }
</script>
<style scoped>
  #log-detail{
    margin-top: 60px;
  }
</style>
